package com.twu.biblioteca;

import java.util.Date;

/**
 * Created by xndong on 10/2/14.
 */
public class Item {
    public String Name;
    public String Author;
    public int  PublishYear;
    public boolean IsCheckOut;

    public long Id;
    private static int Count =0;
    private Customer LastUser;

    public Item(String name, String author, int publishYear, boolean isCheckout){
        Name = name;
        Author = author;
        PublishYear = publishYear;
        IsCheckOut = isCheckout;
        Id = GenerateId();
    }

    private long GenerateId() {return ++Count;}

    public void CheckOut(Customer customer){
        if (this.IsCheckOut) Show.Message("That book is not available.");
        this.IsCheckOut = true;
        this.LastUser = customer;
        Show.Message("Thank you! Enjoy the book.");
    }

    public void Return(Customer customer){
        if (!this.IsCheckOut) Show.Message("That is not a valid book to return.");
        if (LastUser.equals(customer))
        this.IsCheckOut = false;
        Show.Message("Thank you for returning the book.");
    }
}
